package concurrent;

import java.util.concurrent.TimeUnit;

/**
 * @author jack.wu
 * @since 2019/12/25 16:37
 */
public class ThreadGroupDemo {

    public static class T1 implements Runnable {
        @Override
        public void run() {
            System.out.println("ThreadName - "+ Thread.currentThread().getName());
            try {
                TimeUnit.SECONDS.sleep(3);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public static void main(String[] args) throws InterruptedException {
        ThreadGroup threadGroup = new ThreadGroup("Demo Thread Group");
        T1 t1 = new T1();
        Thread thread = new Thread(threadGroup,t1);
        thread.setName("线程1");
        thread.start();
        TimeUnit.SECONDS.sleep(1);
        System.out.println("活动线程数："+threadGroup.activeCount());
        System.out.println("活动线程组："+threadGroup.activeGroupCount());
        System.out.println("线程组名称："+threadGroup.getName());
    }
}
